﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Windows;
using System.Windows.Forms;
using ReflectionStudio.Core.Events;
 using ReflectionStudio.Core.Database;
using System.Data.OracleClient;
namespace WPFExcelReport
{
   

    public class TrisType
    {
        public string TrisCode = "";
        public string TrisDirect = "";
        public string Description = "";
        public TrisType(string triscode, string trisdirect, string description)
        {
            TrisCode = triscode;
            TrisDirect = trisdirect;
            Description = description;
        }
    }
    public class GBInventory
    {
        public string INVDATE;
        public string ARTICLE;
        public string VAR;
        public string COLOR;
        public string SPPART;
        public string FBPART;
        public double LASTWEI;
        public GBInventory()
        {
        }
        public GBInventory(string invdate,string article,string color,string sppart,string fbpart,double lastwei,string var="  ")
        {
            INVDATE = invdate;
            ARTICLE = article;
            VAR = var;
            COLOR = color;
            SPPART = sppart;
            FBPART = fbpart;
            LASTWEI = lastwei;
        }

    }
    public class WBInventory
    {
        #region ----------SUN------------------
        public string ARTICLE;
        public string FINISH;
        public string MATSOURCE, MATLOT = ""; 
 
        public string WH;
        public string WBBWAKZ;
        public int STARTPCNUM = 0;
        public double STARTQTY;

        public int MOVINPCNUM = 0;
        public double MOVINQTY;
        public int MOVOUTPCNUM = 0;
        public double MOVOUTQTY;

        public int ENDPCNUM = 0;
        public double ENDQTY;
        #endregion
        public string Article;
        public string INVDATE;
        public string LASTINVDATE;
        public string WBBDPART;
        public int LastPcNum = 0;
        public double lastQtyMtr;
        public string WBBLO;
        public WBInventory()
        {
        }
        public WBInventory(string invdate, string wblo, string article, string wbbdpart, int lastpcnum, double lastqtymtr)
        {
            WBBLO = wblo;
            INVDATE = invdate;
            Article = article;
            LastPcNum = lastpcnum;
            lastQtyMtr = lastqtymtr;
            WBBDPART = wbbdpart;
        }
        public WBInventory(string invdate, string wblo, string wBBWAKZ,string article, string _FINISH, string wbbdpart, int lastpcnum, double lastqtymtr)
        {
            WH = wblo;
            INVDATE = invdate;
            WBBWAKZ = wBBWAKZ;
            ARTICLE = article;
            FINISH = _FINISH;
            WBBDPART = wbbdpart;
            ENDPCNUM = lastpcnum;
            ENDQTY = lastqtymtr;
            MATSOURCE = wbbdpart;
            STARTPCNUM = lastpcnum;
            STARTQTY = lastqtymtr;
        }
        //(lastInvDate, WBBLO, ARTICLE,FINISH, WBBDPART, INVPCNUM, INVQTYMTR);
        public WBInventory(string invdate, string wblo, string wBBWAKZ, string article, string wbbdpart, int lastpcnum, double lastqtymtr)
        {
            WH = wblo;
            INVDATE = invdate;
            WBBWAKZ = wBBWAKZ;
            ARTICLE = article;
            ENDPCNUM = lastpcnum;
            ENDQTY = lastqtymtr;
            MATSOURCE = wbbdpart;
            STARTPCNUM = lastpcnum;
            STARTQTY = lastqtymtr;
        }
    }
    public class GBMOVEMENT
    {
        public int ICCGLDAT;
        public string ARTICLE;
        public string ATRICLEDES;
        public string COLOR;
        public string COLORDES;
        public string SPPART;
        public string FBPART;
        public string TYPE;
        public string SUPPLIER;
        public string DES;
        public string ORDERNO;
        public double STARTWEI;
        public double INWEI;
        public double OUTWEI;
        public double ADJWEI;
        public double ENDWEI;
        public GBMOVEMENT()
        {
        }
        public GBMOVEMENT(int ICCGLDAT, string ARTICLE, string ARTICLEDES, string COLOR, string COLORDES, string SPPART, string FBPART, string TYPE, string SUPPLIER, string DES, string ORDERNO, double STARTWEI, double INWEI, double OUTWEI, double ADJWEI, double ENDWEI)
        {
            ICCGLDAT = ICCGLDAT;
            ARTICLE = ARTICLE;
            ARTICLEDES = ARTICLEDES;
            COLOR = COLOR;
            COLORDES = COLORDES;
            SPPART = SPPART;
            FBPART = FBPART;
            TYPE = TYPE;
            SUPPLIER = SUPPLIER;
            DES = DES;
            ORDERNO = ORDERNO;
            STARTWEI = STARTWEI;
            INWEI = INWEI;
            OUTWEI = OUTWEI;
            ADJWEI = ADJWEI;
            ENDWEI = ENDWEI;
        }

    }
    public class WBMOVEMENT
    {
        public int ICCWBMDAT;
        public string ICCWBMTYPE;
        public string ICCWBMWAKZ;
        public string ICCWBMBS;
        public int ICCWBMBELEG;
        public string ARTICLE;
        public string ICCWBMBESCHICH;
        public string ICCWBMDPART;
        public string ICCWBMCODE;
        public string ICCWBMNAME;
        public string ICCWBMBDES;
        public string ICCWBMAUFTYP;
        public string ORDERNO;
        public double STARTMTR;
        public int STARTPCNUM;
        public double INMTR;
        public int INPCNUM;
        public double OUTMTR;
        public int OUTPCNUM;
        public double ADJMTR;
        public double ENDMTR;
        public int ENDPCNUM;
        public WBMOVEMENT()
        {
        }
        public WBMOVEMENT(int ICCWBMDAT,string ICCWBMTYPE,string ICCWBMWAKZ,string ICCWBMBS,int ICCWBMBELEG,string ARTICLE,string ICCWBMBESCHICH,string ICCWBMDPART,string ICCWBMCODE,string ICCWBMNAME,string ICCWBMBDES,string ICCWBMAUFTYP,string ORDERNO,double STARTMTR,int STARTPCNUM,double INMTR,int INPCNUM,double OUTMTR,int OUTPCNUM,double ADJMTR,double ENDMTR,int ENDPCNUM)
        {
            ICCWBMDAT = ICCWBMDAT;
            ICCWBMTYPE = ICCWBMTYPE;
            ICCWBMWAKZ = ICCWBMWAKZ;
            ICCWBMBS = ICCWBMBS;
            ICCWBMBELEG = ICCWBMBELEG;
            ARTICLE = ARTICLE;
            ICCWBMBESCHICH = ICCWBMBESCHICH;
            ICCWBMDPART = ICCWBMDPART;
            ICCWBMCODE = ICCWBMCODE;
            ICCWBMNAME = ICCWBMNAME;
            ICCWBMBDES = ICCWBMBDES;
            ICCWBMAUFTYP = ICCWBMAUFTYP;
            ORDERNO = ORDERNO;
            STARTMTR = STARTMTR;
            STARTPCNUM = STARTPCNUM;
            INMTR = INMTR;
            INPCNUM = INPCNUM;
            OUTMTR = OUTMTR;
            OUTPCNUM = OUTPCNUM;
            ADJMTR = ADJMTR;
            ENDMTR = ENDMTR;
            ENDPCNUM = ENDPCNUM;
        }
    }
    public class WGSummary
    {
        public string FACTORY;
        public string ARTICLE;
        public string WBBDPART;
        public string WBEWBESCHICH;
        public string COLORDES;
        public int PCNUM;
        public double WBEWMTR;
        public WGSummary()
        { }
        public WGSummary(string article, string wbbdpart, int pcnum, double wbewmtr)
        {
            ARTICLE = article;
            WBBDPART = wbbdpart;
            PCNUM = pcnum;
            WBEWMTR = wbewmtr;
        }
        public WGSummary(string factory,string article, string wbbdpart, int pcnum, double wbewmtr)
        {
            FACTORY = factory;
            ARTICLE = article;
            WBBDPART = wbbdpart;
            PCNUM = pcnum;
            WBEWMTR = wbewmtr;
        }
        public WGSummary(string factory, string article, string wbewbeschich, string wbbdpart, int pcnum, double wbewmtr)
        {
            FACTORY = factory;
            ARTICLE = article;
            WBEWBESCHICH = wbewbeschich;
            WBBDPART = wbbdpart;
            PCNUM = pcnum;
            WBEWMTR = wbewmtr;
        }
        public WGSummary(string factory, string article, string wbewbeschich,string colordes, string wbbdpart, int pcnum, double wbewmtr)
        {
            FACTORY = factory;
            ARTICLE = article;
            WBEWBESCHICH = wbewbeschich;
            COLORDES = colordes;
            WBBDPART = wbbdpart;
            PCNUM = pcnum;
            WBEWMTR = wbewmtr;
        }
    }
    public class BaseReport
    {
        public IntexReptServBLClient proxy;
        public OracleConnection OracleDB;
        public string strCompany = "";
        public string strExcelFile = "";
        public string Standard = "";
        public string TemplatePath = "";
        public string Root = @"R:\";
        public string destfolder = "Sales";
        public string PrintType = "JustExcel";
        public string UserID;
        public string date = "";
        public string year = "";
        public string month = "";
        public string day = "";
        ~BaseReport()
        {
            if (exAgent != null)
            {
                exAgent.Close();
            }
        }
        public string filename = "";
        public ArrayList columns = new ArrayList();
        public ExcelX.ExcelLib.ExcelAgent exAgent;        
        public DataSet dsSource;
        public Dictionary<string, object> dicSource;
        public Dictionary<string, object> dicOrigion;
        public string PatternStringFinal = "";
        public string PatternTables = "WTSAER;WTLEIST;WTSCHUSS;";
        public string[] WA = new string[] { "A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V" };

        public int RowsHide = 0;
        #region Pattern
        public Dictionary<string, string> PatternMatrix(int x, int y, bool IsWarp)
        {
            Dictionary<string, string> WarpMatrix = new Dictionary<string, string>();
            string Rows = "A";
            string Column = "01";

            for (int i = 0; i < x; i++)
            {
                for (int j = 0; j < y; j++)
                {
                    string WBj = Right("000" + (j + 1).ToString(), 3);
                    WarpMatrix.Add("W" + WA[i] + WBj, "0");
                }
            }
            return WarpMatrix;
        }
        public string BuildPatternString(Array WR, Array WM, string TableName)
        {
            string YarnSequence = "";
            string Yarn = "";
            int YarnNum = 0;
            int YarnR = 0;
            try
            {
                if (!PatternTables.Contains(TableName))
                {
                    return YarnSequence;
                }
                WR = HandleWR(WR);
                for (int WRy = 0; WRy < 698; WRy++)
                {
                    Yarn = "";
                    for (int WRx = 0; WRx < 22; WRx++)
                    {
                        YarnNum = (int)WM.GetValue(WRx, WRy);
                        if (YarnNum > 0)
                        {
                            Yarn = WA[WRx];
                            Yarn += YarnNum.ToString();
                        }
                    }
                    if (Yarn != "")
                    {
                        for (int WRz = 0; WRz < 4; WRz++)
                        {
                            YarnR = (int)WR.GetValue(WRz, WRy);
                            if (YarnR == 0)
                            {
                                YarnR = 1;
                            }
                            //if (YarnR > 0)
                            {
                                Yarn = "(" + Yarn + ")" + YarnR.ToString();
                            }
                        }
                        YarnSequence += "+" + Yarn;
                    }
                    YarnSequence = YarnSequence.Replace("++", "");
                }
            }

            catch (Exception ex)
            {
                Tracer.Error(ex.StackTrace, ex);
            }
            //YarnSequence = Left(YarnSequence, YarnSequence.Length - 1);
            //YarnSequence = CombinePattern(YarnSequence);
            TreeNode RootNode = new TreeNode();
            RootNode = BuildPatternTree(YarnSequence, RootNode);

            RootNode = BuildTreeText(RootNode);
            PatternStringFinal = RootNode.Text;

            if (PatternStringFinal.StartsWith("+"))
            {
                PatternStringFinal = Right(PatternStringFinal, PatternStringFinal.Length - 2);
            }
            YarnSequence = PatternStringFinal.Replace("-", "");
            return YarnSequence;
        }
        public int FindSubNode(TreeNode FatherNode)
        {
            int NumGrandNodes = 0;
            foreach (TreeNode SonNode in FatherNode.Nodes)
            {
                foreach (TreeNode GrandSonNode in SonNode.Nodes)
                {
                    NumGrandNodes++;
                }
            }
            return NumGrandNodes;
        }
        public TreeNode FillInNodeText(TreeNode FatherNode)
        {
            int NumGrandNodes = 0;
            string SonText = "";
            bool FsonText = false;
            if (FatherNode.Text == "")
            {
                FsonText = true;
                foreach (TreeNode TXSon in FatherNode.Nodes)
                {
                    if (Right(TXSon.Text, TXSon.Text.Length - 1) != "")
                    {
                        SonText += Right(TXSon.Text, TXSon.Text.Length - 1) + "+";
                    }
                    else
                    {
                        FsonText = false;
                        SonText = "";
                    }
                }

                if (!FsonText)
                {
                    foreach (TreeNode TNSon in FatherNode.Nodes)
                    {
                        FillInNodeText(TNSon);
                    }
                    FillInNodeText(FatherNode);
                }
                else
                {
                    SonText += "***";
                    SonText = SonText.Replace("+***", "");
                    if (FatherNode.Name == ")1")
                    {
                        FatherNode.Text = "+" + SonText;
                    }
                    else
                    {
                        FatherNode.Text = "+(" + SonText + FatherNode.Name;
                    }
                    return FatherNode;
                }
            }
            return FatherNode;
        }
        public TreeNode BuildTreeText(TreeNode FatherNode)
        {
            //如果父节点的儿子个数>0,则没有找到最小级别
            //如果儿子数=0，已经是最小级别，需要向上
            string SonText = "";
            FatherNode = FillInNodeText(FatherNode);
            return FatherNode;
        }
        public string SplitPattern(string YarnSequence)
        {

            string A, B, BNA, StrOut = "", SameSequence;
            string SemiTarget = "";
            int LastPlus = 0;
            int LastCommaLofA = 0;
            int LastCommaRofA = 0;
            int LastSequenceofB = 0;
            int YLen = 0;
            bool flagF = true;
            bool flagC = true;
            //YarnSequence = "( ( ( ( A2)20)1)1)1+( ( ( ( B2)20)1)1)1+( ( ( ( A4)5)1)1)1+( ( ( ( B4)5)1)1)1+( ( ( ( C2)1)1)1)1+( ( ( ( A4)6)1)1)1+( ( ( ( B4)6)1)1)1";
            //假设字符串是((((A4)6)1)1)1+((((B5)5)1)1)1+((((C2)6)1)1)1+((((D3)6)1)1)1

            YLen = YarnSequence.Length;
            LastPlus = YarnSequence.LastIndexOf("+");
            //* 1>在后面找到第一个“+((((”，截取字符串A="((((D3)6)1)1)1"
            A = Right(YarnSequence, YLen - LastPlus);
            LastCommaRofA = A.LastIndexOf(")");
            //* 2>从后面找到第一个"）"，获取字符串"）1"
            flagF = true;
            SameSequence = Right(A, A.Length - LastCommaRofA);
            if (!SameSequence.Contains(")"))
            {
                //此时字符串已经无需继续合并
                flagF = false;
                flagC = false;
                A = "";
            }
            else
            {
                YarnSequence = Left(YarnSequence, LastPlus);
            }
            #region 首次合并，可能仅对字符串一部分进行合并
            while (YarnSequence.Length > 0 && flagF)
            {
                //* 3>原字符串截取找到第一个“+((((”，截取字符串B=“((((C2)6)1)1)1”，并改变为B=B+"*"
                YLen = YarnSequence.Length;
                LastPlus = YarnSequence.LastIndexOf("+");
                B = Right(YarnSequence, YLen - LastPlus);
                B = B + "#";
                YarnSequence = Left(YarnSequence, LastPlus);

                LastSequenceofB = B.LastIndexOf(SameSequence + "#");
                if (LastSequenceofB > 0) //* 4>如果字符串B存在“）1*”
                {
                    //* 4.1>进行B字符串“）1*”替换为空“”，此时字符串B变为“+((((C2)6)1)1”，
                    B = Left(B, LastSequenceofB);
                    //* 4.2>字符串A去除左边第一个“（”
                    A = Right(A, A.Length - 2);
                    //* 4.3>字符串B+A=“((((C2)6)1)1+(((D3)6)1)1)1”
                    BNA = B + "+" + A;
                    BNA = BNA.Replace("++", "+");
                    A = BNA;
                    flagF = true;
                }
                else//* 5>如果字符串B不存在“）1*”，补充原来的字符串。
                {
                    B = Left(B, B.Length - 1);
                    YarnSequence = YarnSequence + B;
                    flagF = false;

                }
            }// * 5.1>对于新字符串C，去除左边第一个（和后面的）1之后，继续1>,直到没有匹配项之后，恢复字符串格式
            #endregion
            return YarnSequence;
        }
        public TreeNode BuildPatternTree(string YarnSequence, TreeNode RootNode)
        {
            string strL, strR, strOut, strIN;
            TreeNode nodeR;
            string StrNew = "";
            string SameSequence;
            string SemiTarget = "";

            int LastCommaLofA = 0;
            int LastCommaRofA = 0;

            // 字符串YQ=( ( ( ( A2)20)1)1)1+( ( ( ( B2)20)1)1)1+( ( ( ( A4)5)1)1)1+( ( ( ( B4)5)1)1)1+( ( ( ( C2)1)1)1)1+( ( ( ( A4)6)1)1)1+( ( ( ( B4)6)1)1)1
            //1>首先建立根节点X1
            //2>解读字符串YQ，对于分解的字符，创建新的节点，对于原字符串则继续解读。
            //3>对于新的节点，做为字符串继续解读
            strL = SplitPattern(YarnSequence);
            strR = Right(YarnSequence, YarnSequence.Length - strL.Length);
            strIN = strR;
            if (strR.Length == 0)
            {
                nodeR = new TreeNode();
                nodeR.Text = strL;
                RootNode.Nodes.Add(nodeR);
                return RootNode;
            }
            if (strL.Length > 0)//不可以在这次循环中合并部分，需要再次拆分
            {
                BuildPatternTree(strL, RootNode);
            }
            if (strR.Length > 0)//可合并部分
            {
                strOut = CombinePatternRight(strIN);
                if (strOut.Length > 0)
                {
                    SemiTarget = strOut;
                    LastCommaRofA = SemiTarget.LastIndexOf(")");
                    LastCommaLofA = SemiTarget.IndexOf("(");
                    SameSequence = Right(SemiTarget, SemiTarget.Length - LastCommaRofA);
                    StrNew = SemiTarget.Substring(LastCommaLofA + 1, LastCommaRofA - LastCommaLofA - 1);
                    if (!StrNew.StartsWith("+"))
                    {
                        StrNew = "+" + StrNew;
                    }
                    nodeR = new TreeNode();
                    nodeR.Name = SameSequence;
                    RootNode.Nodes.Add(nodeR);
                    BuildPatternTree(StrNew, nodeR);
                }
            }
            else
            {
            }

            return RootNode;
        }

        public string CombinePatternRight(string YarnSequence)
        {

            string A, B, BNA, StrOut = "", SameSequence;
            string SemiTarget = "";
            int LastPlus = 0;
            int LastCommaLofA = 0;
            int LastCommaRofA = 0;
            int LastSequenceofB = 0;
            int YLen = 0;
            bool flagF = true;
            bool flagC = true;
            //YarnSequence = "( ( ( ( A2)20)1)1)1+( ( ( ( B2)20)1)1)1+( ( ( ( A4)5)1)1)1+( ( ( ( B4)5)1)1)1+( ( ( ( C2)1)1)1)1+( ( ( ( A4)6)1)1)1+( ( ( ( B4)6)1)1)1";
            //假设字符串是((((A4)6)1)1)1+((((B5)5)1)1)1+((((C2)6)1)1)1+((((D3)6)1)1)1

            YLen = YarnSequence.Length;
            LastPlus = YarnSequence.LastIndexOf("+");
            //* 1>在后面找到第一个“+((((”，截取字符串A="((((D3)6)1)1)1"
            A = Right(YarnSequence, YLen - LastPlus);
            LastCommaRofA = A.LastIndexOf(")");
            //* 2>从后面找到第一个"）"，获取字符串"）1"
            flagF = true;
            SameSequence = Right(A, A.Length - LastCommaRofA);
            if (!SameSequence.Contains(")"))
            {
                //此时字符串已经无需继续合并
                flagF = false;
                flagC = false;
                A = "";
            }
            else
            {
                YarnSequence = Left(YarnSequence, LastPlus);
            }
            SemiTarget = "";
            #region 首次合并，可能仅对字符串一部分进行合并
            while (YarnSequence.Length > 0 && flagF)
            {
                //* 3>原字符串截取找到第一个“+((((”，截取字符串B=“((((C2)6)1)1)1”，并改变为B=B+"*"
                YLen = YarnSequence.Length;
                LastPlus = YarnSequence.LastIndexOf("+");
                B = Right(YarnSequence, YLen - LastPlus);
                B = B + "#";
                YarnSequence = Left(YarnSequence, LastPlus);

                LastSequenceofB = B.LastIndexOf(SameSequence + "#");
                if (LastSequenceofB > 0) //* 4>如果字符串B存在“）1*”
                {
                    //* 4.1>进行B字符串“）1*”替换为空“”，此时字符串B变为“+((((C2)6)1)1”，
                    B = Left(B, LastSequenceofB);
                    //* 4.2>字符串A去除左边第一个“（”
                    A = Right(A, A.Length - 2);
                    //* 4.3>字符串B+A=“((((C2)6)1)1+(((D3)6)1)1)1”
                    BNA = B + "+" + A;
                    BNA = BNA.Replace("++", "+");
                    A = BNA;
                    flagF = true;
                }
                else//* 5>如果字符串B不存在“）1*”，补充原来的字符串。
                {
                    B = Left(B, B.Length - 1);
                    YarnSequence = YarnSequence + B;
                    flagF = false;

                }
            }// * 5.1>对于新字符串C，去除左边第一个（和后面的）1之后，继续1>,直到没有匹配项之后，恢复字符串格式
            #endregion
            return A;
        }

        public Array HandleWR(Array WR)
        {
            int CurrentR = 0;
            int LastR = 0;
            int ColR = 697;
            try
            {
                for (int WRx = 0; WRx < 4; WRx++)
                {
                    CurrentR = 0;
                    LastR = 0;
                    for (int WRy = 0; WRy < 698; WRy++)
                    {
                        CurrentR = (int)WR.GetValue(WRx, ColR - WRy);
                        if (CurrentR == 0
                            && LastR != 0)
                        {
                            WR.SetValue(LastR, WRx, ColR - WRy);
                        }
                        if (CurrentR > 0)
                        {
                            if (CurrentR == LastR
                                && CurrentR != 1
                                )
                            {
                                LastR = 0 - LastR;
                                WR.SetValue(LastR, WRx, ColR - WRy);
                            }
                            else
                            {
                                LastR = CurrentR;
                            }
                        }
                    }
                }

            }
            catch (Exception ex)
            {
                Tracer.Error(ex.StackTrace, ex);
            }
            return WR;
        }
        #endregion
        public BaseReport()
        {
        }
        #region Tools
        public string Divide(string value, int times)
        {
            string srt = "";
            try
            {
                if (value.ToString().Trim() == "")
                    srt = "0";
                srt = (System.Convert.ToDecimal(value.ToString()) / times).ToString();
            }
            catch (Exception ex)
            {
                Tracer.Error(ex.StackTrace, ex);
            }
            return srt;
        }
        public string GetGB2312Value(string strSource)
        {
            byte[] b;
            string filevalue = "";
            b = Encoding.GetEncoding("ISO-8859-1").GetBytes(strSource);
            filevalue = Encoding.GetEncoding("gb2312").GetString(b);
            return filevalue;
        }
        public void FillInCellbyQueue(Queue CellQueue, DataRow dwSource)
        {
            while (CellQueue.Count > 0)
            {
                string CellName = CellQueue.Dequeue() as string;
                string ColumnName = CellQueue.Dequeue() as string;
                string CellValue = GetGB2312Value(dwSource[ColumnName].ToString().Trim());
                exAgent.SetCellValue(CellName, CellValue, true);
            }
        }
        public void FillInCellbyQueue(Queue CellQueue)
        {
            while (CellQueue.Count > 0)
            {
                string CellName = CellQueue.Dequeue() as string;
                string CellValue = CellQueue.Dequeue() as string;
                exAgent.SetCellValue(CellName, CellValue, true);
            }
        }
        public string Right(string str, int num)
        {
            try
            {
                int leng = str.Length;
                str = str.Substring(leng - num, num);
            }
            catch (Exception ex)
            {
            }
            return str;
        }
        public string Left(string str, int num)
        {
            try
            {
                int leng = str.Length;
                str = str.Substring(0, num);
            }
            catch (Exception ex)
            {
                Tracer.Error(ex.StackTrace, ex);
            }
            return str;
        }
        #endregion
        public string GetYarnDes(DataTable dtGSCOLOR, string Yarn)
        {
            string YarnDes = "";
            try
            {
                foreach (DataRow dwGSCOLOR in dtGSCOLOR.Rows)
                {
                    string GSCART = GetGB2312Value(dwGSCOLOR["GSCART"].ToString().Trim());
                    string GSCVAR = GetGB2312Value(dwGSCOLOR["GSCVAR"].ToString().Trim());
                    string GSCFARBE = GetGB2312Value(dwGSCOLOR["GSCFARBE"].ToString().Trim());
                    string GSCBEZ = GetGB2312Value(dwGSCOLOR["GSCBEZ"].ToString().Trim());
                    if (Yarn == GSCART + "/" + GSCVAR + "/" + GSCFARBE)
                    {
                        YarnDes = GSCBEZ;
                    }
                }
            }
            catch (Exception ex)
            {

                Tracer.Error(ex.StackTrace, ex);
            }
            return YarnDes;
        }
        public string Byte2String(byte[] arrByte)
        {

            StringBuilder sb = new StringBuilder();

            foreach (byte b in arrByte)
            {

                sb.Append(b > 15 ? Convert.ToString(b, 16) : '0' + Convert.ToString(b, 16));

            }

            return sb.ToString();

        }
        public void FillInData(ArrayList columns, DataTable dtSoruce,int xStart=2,int yStart=1)
        {
            try
            {
                int x = xStart, y = yStart; 
                foreach (DataRow dataRow in dtSoruce.Rows)
                {
                    y = yStart; 
                    foreach (string columni in columns)
                    {
                        exAgent.SetCellValue(x, y, dataRow[columni].ToString());
                        y++;
                    }
                    x++;
                }
            }
            catch (Exception ex)
            {
                Tracer.Error(ex.StackTrace, ex);
            }
        }
        public virtual void SetValue(int x, int y, string value)
        {
            exAgent.SetCellValue(x, y, value);
        }
        public BaseReport(Dictionary<string, object> dicParamater)
        {
            dicOrigion = dicParamater;
        }
        public virtual void WriteExcelReport(string fileType)
        {
            try
            {
                PrintType = fileType;

                if (exAgent != null)
                {
                    string instancefile = exAgent.FileName;
                    if (PrintType == "DirectPrint")
                    {
                        exAgent.PrintOut(instancefile);
                    }
                    exAgent.Save();
                    //exAgent.SaveAsFile(exAgent.FileName+1, "XLS2003", "ITX");
                    exAgent.Close();
                    
                    if (PrintType == "OpenExcel")
                    {
                        Tracer.Verbose("WriteExcelReport", instancefile);
                        System.Diagnostics.Process.Start("EXCEL.EXE", instancefile);
                        
                    }
                }
            }
            catch (Exception ex)
            {
                Tracer.Error(ex.StackTrace, ex);
            }
        }
        public virtual string SetFolder(string root, string sub)
        {
           return Helpers.Helper.CheckDirectory(root, sub);           
           
        }
    }

}
